// 简单的JavaScript测试文件
console.log('JavaScript测试文件加载成功');

// 测试API连接
async function testAPI() {
    console.log('开始测试API连接...');

    try {
        const response = await fetch('/api/v1/system/info');
        console.log('API响应状态:', response.status);

        if (response.ok) {
            const data = await response.json();
            console.log('API响应数据:', data);
            document.getElementById('test-result').innerHTML = `
                <div style="color: green;">
                    <h3>✅ API连接成功</h3>
                    <p>系统名称: ${data.name}</p>
                    <p>系统版本: ${data.version}</p>
                </div>
            `;
        } else {
            console.error('API响应错误:', response.statusText);
            document.getElementById('test-result').innerHTML = `
                <div style="color: red;">
                    <h3>❌ API连接失败</h3>
                    <p>状态码: ${response.status}</p>
                    <p>错误信息: ${response.statusText}</p>
                </div>
            `;
        }
    } catch (error) {
        console.error('API连接异常:', error);
        document.getElementById('test-result').innerHTML = `
            <div style="color: red;">
                <h3>❌ API连接异常</h3>
                <p>错误信息: ${error.message}</p>
            </div>
        `;
    }
}

// 页面加载完成后执行测试
document.addEventListener('DOMContentLoaded', function() {
    console.log('DOM加载完成，开始测试...');
    document.getElementById('test-info').innerHTML = `
        <p>当前时间: ${new Date().toLocaleString()}</p>
        <p>用户代理: ${navigator.userAgent}</p>
        <p>页面URL: ${window.location.href}</p>
    `;

    // 延迟1秒后测试API
    setTimeout(testAPI, 1000);
});